/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package randomiofile;

import java.awt.FileDialog;
import java.awt.Frame;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 *
 * @author pfares
 */
public class Main extends Frame {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        new Main().run(args);
    }

    public void run(String args[]) throws IOException {
        FileDialog fd = new FileDialog(this);
        fd.setMode(FileDialog.LOAD);
        fd.setVisible(true);
        String nom = fd.getFile();
        String dir = fd.getDirectory();
        System.out.println("Le fichier choisi est "+dir + "/"+nom);
        DataInputStream iFile = new DataInputStream(new BufferedInputStream(new FileInputStream(dir+"/"+nom)));
        RandomAccessFile oFile = new RandomAccessFile(args[0], "rw");
        oFile.seek(oFile.length());
        String ligne;
        while ((ligne = iFile.readUTF()) != null) {
            oFile.writeBytes(ligne);
            oFile.writeByte('\n');
        }
        oFile.close();
        
    }
}
